package jfuzzyprincepless.zarchive.negotiation.protocols;

import jfuzzyprincepless.zarchive.algorithm.structure.ICommandConstruction;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.zarchive.negotiation.protocols.IFilter;

public class FilteringNegotiationProtocol
	implements INegotiationProtocol__Q_del
{
	private IFilter filter;
	private INegotiationProtocol__Q_del subProtocol;

	public FilteringNegotiationProtocol(
		IFilter filter,
		INegotiationProtocol__Q_del subProtocol
	) {
		this.filter = filter;
		this.subProtocol = subProtocol;
	}

	@Override
	public INegotiation createNegotiation(
		ICommandConstruction construction,
		INegotiationContext context
	) {
		if (filter.accepts(construction)) {
			return subProtocol.createNegotiation(construction, context);
		} else {
			return null;
		}
	}
}
